'use strict';
let Response = require('../../../model/Response');
let RestifyProxy = require('../../../util/RestifyProxy');
let CustomPageBean = require('../../../model/CustomPageBean');
let groupsService = require('../../../service/operate/groupsService');
let logger = require('../../../util/LoggerUtil').logger('groupsController.js');

/**
 * 分组管理——页面
 */
module.exports.groupsPage = function () {
    let response = new Response();
    response.render('back/operate/groups/groups');//html路径
    this.resolve(response);
};

/**
 * 分组管理——列表数据
 */
module.exports.groupsList = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await groupsService.groupsList(this, params);
        let pageBean = new CustomPageBean(result);
        response.send(pageBean);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};

/**
 * 分组管理-创建页面
 */
module.exports.groupsCreatePage = function () {
    let response = new Response();
    response.render('back/operate/groups/groups_create');
    this.resolve(response);
};
/*分组管理-创建页面-保存按钮*/
module.exports.groupsCreateSave = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await groupsService.groupsCreateSave(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};

/**
 * 分组管理-详情页面
 */
module.exports.groupsDetailPage = function () {
    let response = new Response();
    response.render('back/operate/groups/groups_detail');
    this.resolve(response);
};
/*分组管理-详情页面-获取详情数据*/
module.exports.groupsDetail = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await groupsService.groupsDetail(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};
/*分组管理-详情页面-获取详情列表*/
module.exports.groupsDetailList = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await groupsService.groupsDetailList(this, params);
        let pageBean = new CustomPageBean(result);
        response.send(pageBean);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};

/*分组管理-详情页面-查看照明计划的页面*/
module.exports.groupsPlanPage = function () {
    let response = new Response();
    response.render('back/operate/groups/groups_plan');
    this.resolve(response);
};
/*分组管理-详情页面-获取照明计划数据*/
module.exports.groupsPlanList = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await groupsService.groupsPlanList(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};

/**
 * 分组管理-修改页面
 */
module.exports.groupsUpdatePage = function () {
    let response = new Response();
    response.render('back/operate/groups/groups_update');
    this.resolve(response);
};
/*分组管理-修改页面-确认按钮*/
module.exports.groupsUpdateSave = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await groupsService.groupsUpdateSave(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};

/*分组管理-修改页面-转移分组下拉框*/
module.exports.groupsUpdateList = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await groupsService.groupsUpdateList(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};

/*分组管理-修改页面-转移分组按钮*/
module.exports.groupsUpdateConfirm = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await groupsService.groupsUpdateConfirm(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};

/*分组管理-修改页面-照明计划的修改确认按钮*/
module.exports.planConfirm = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await groupsService.planConfirm(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};
/*分组管理-修改页面-照明计划的保存按钮*/
module.exports.planSave = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await groupsService.planSave(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};

/**
 * 分组管理-删除按钮
 */
module.exports.groupsDelete = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await groupsService.groupsDelete(this, params.groupCode);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};
